package com.hubery.designpattern.design.template.gant;

import com.hubery.designpattern.enums.UserTypeEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.EnumMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * @author: lxy
 * @date: 2023/2/27 23:03
 * @Description:
 */
@Slf4j
@Component
public class GantPrizeTemplateSupport {

    @Resource
    private List<AbstractGantPrizeTemplate> gantPrizeTemplateList;

    private Map<UserTypeEnum, AbstractGantPrizeTemplate> gantPrizeTemplateMap = new EnumMap<>(UserTypeEnum.class);

    @PostConstruct
    public void init() {
        gantPrizeTemplateMap = gantPrizeTemplateList.stream().collect(Collectors.toMap(AbstractGantPrizeTemplate::getUserTypeEnum, Function.identity()));
    }

    public AbstractGantPrizeTemplate getGantPrizeTemplateService(UserTypeEnum typeEnum) {
        return gantPrizeTemplateMap.getOrDefault(typeEnum, null);
    }
}
